import datetime
from django.test import TestCase
from django.test.client import Client

"""
Testira statistike
"""
class StatisticsTestCase(TestCase):
    
    def setUp(self):
        pass

    def runTest(self):
        self.testChessStatistics()
        self.testTableFootballStatistics()

    def testChessStatistics(self):
        c = Client()
        c.login(username='kokan', password='123')
        
        response = c.get("/mdcs/statistics/chess/")
        self.assertTrue(response != None)
        self.assertTrue(response.context != None)
        self.assertEqual(len(response.context), 2)
        self.assertTrue(response.context[0]["chess_stat"] != None)
        
        chess_stats = response.context[0]["chess_stat"]
        self.assertEqual(1, len(chess_stats.best_users))
        self.assertEqual(4, chess_stats.best_users[0].id)
        self.assertEqual(2, chess_stats.last_played_match.id)
        self.assertEqual(1, len(chess_stats.worst_users))
        self.assertEqual(2, chess_stats.worst_users[0].id)

    def testTableFootballStatistics(self):
        c = Client()
        c.login(username='kokan', password='123')
        
        response = c.get("/mdcs/statistics/table_football/")
        self.assertTrue(response != None)
        self.assertTrue(response.context != None)
        self.assertEqual(len(response.context), 2)
        self.assertTrue(response.context[0]["tf_stat"] != None)
        
        tf_stats = response.context[0]["tf_stat"]
        self.assertEqual(2, len(tf_stats.best_users))
        self.assertEqual(5, tf_stats.best_users[0].id)
        self.assertEqual(6, tf_stats.best_users[1].id)
        self.assertEqual(6, tf_stats.last_played_match.id)
        self.assertEqual(2, len(tf_stats.worst_users))
        self.assertEqual(8, tf_stats.worst_users[0].id)
        self.assertEqual(7, tf_stats.worst_users[1].id)
